#include "../Core/MediaManager.h"

using namespace std;

namespace epix {

SINGLETON_IMPL(MediaManager)

MediaManager::MediaManager()
{
}

MediaManager::~MediaManager()
{
}

string MediaManager::getExtension(const char *filename) const
{
    string extension = "";
    bool find = false;
    int size = strlen(filename);
    for(int i=size-1; i>0 && !find; i--)
    {
        if(filename[i] == '.') find = true;
        else extension = filename[i] + extension;
    }
    return extension;
}

void MediaManager::split(const std::string &string, std::vector<std::string> &tokens, const std::string delim)
{
    tokens.clear();

    for(std::string::size_type p1 = 0, p2 = 0; p1 != std::string::npos;)
    {
        p1 = string.find_first_not_of(delim, p1);
        if(p1 != std::string::npos)
        {
            p2 = string.find_first_of(delim , p1);
            tokens.push_back(string.substr(p1, p2 - p1));
            p1 = p2;
        }
    }
}

std::string MediaManager::toLower(const std::string &text)
{
    std::string ret(text.size(), ' ');

    std::transform(text.begin(), text.end(), ret.begin(), static_cast<int (*)(int)>(std::tolower));

    return ret;
}

}
